using UnityEngine;

namespace skeleton
{
    public class WalkState : State
    {
        [SerializeField] float speed;

        // ========================================================================

        public override void Process()
        {
            base.Process();

            if (skeleton.TryChangeState(StateCode.Chase)) return;

            if (skeleton.IsWallDetected() || !skeleton.IsGroundDetected())
            {
                skeleton.Flip();
                skeleton.ChangeState(StateCode.Idle);
                return;
            }

            skeleton.SetVelocity(speed * skeleton.FacingDirection(), skeleton.GetVelocity(1));
        }
    }
}